/* $Id: NewTournamentDialog.java 39 2009-07-24 22:48:06Z h_m_r@gmx.de $ */
package org.jugger.tournament.gui.view;

import java.awt.Component;
import java.awt.Frame;

import javax.swing.JDialog;
import javax.swing.JOptionPane;

import org.jugger.tournament.gui.view.CreateTournamentPanel.CreateTournamentListener;
import org.jugger.tournament.model.Tournament;

import util.I18N;



public class NewTournamentDialog extends JDialog implements CreateTournamentListener {

	private static final long serialVersionUID = -2371399238774495819L;

	private static NewTournamentDialog dialog;
    private static Tournament value;
    private CreateTournamentPanel panel;

    /**
     * Set up and show the dialog.  The first Component argument
     * determines which frame the dialog depends on; it should be
     * a component in the dialog's controlling frame. The second
     * Component argument should be null if you want the dialog
     * to come up with its left corner in the center of the screen;
     * otherwise, it should be the component on top of which the
     * dialog should appear.
     */
    public static Tournament showDialog(Component frameComp,
                                    Component locationComp) {
    	value = null;

        Frame frame = JOptionPane.getFrameForComponent(frameComp);
        dialog = new NewTournamentDialog(frame,
                                locationComp);
        dialog.setVisible(true);
        return value;
    }

    private NewTournamentDialog(Frame frame,
                       Component locationComp) {
        super(frame, I18N.__("createNewTournament"), true);
        panel = new CreateTournamentPanel();
        panel.addCreateTournamentListener(this);
        add(panel);

        pack();
        setSize(650, 400);
        setLocationRelativeTo(locationComp);
    }

	public void performTournamentCreated(Tournament tournament) {
		value = tournament;
		this.setVisible(false);
	}

	public void performAbort() {
		setVisible(false);
	}
}
